<?php
/**
 * Created by PhpStorm.
 * User: LEEYOOL
 * Date: 1/24/15
 * Time: 10:29 PM
 */

class profile_m extends CI_Model {
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }

    public function getUser($id) {
        $sql = "SELECT * FROM `users` WHERE `id` = $id";
        $query = $this->db->query($sql);
        return $query->row();
    }

    public function login($email, $pass)
    {
        $sql="SELECT * FROM `users` WHERE `email` = '$email' AND `password` = '$pass'";
        $query = $this->db->query($sql);
        return $query->row();
    }

    public function createUser($data)
    {
        $this->db->insert('users', $data);
        return $this->db->insert_id();
    }

    public function updateUser($data, $id)
    {
        $this->db->where('id', $id);
        return $this->db->update('users', $data);
    }

    public function checkEmail($email) {
        $sql = "SELECT * FROM `users` WHERE `email` =  '" . $email . "' ";
        $query = $this->db->query($sql);
        return $query->num_rows();
    }

    public function addTour($data)
    {
        return $this->db->insert('calendar', $data);
    }

} 